﻿using System;
using System.Collections.Generic;

namespace TradeClient.Logic.TradeCore
{
    /// <summary>
    /// 交易所需信息字段
    /// </summary>
    public class TradeField
    {
        /// <summary>
        /// 交易时间
        /// </summary>
        public string TradeTime { get; set; }

        /// <summary>
        /// 策略名
        /// </summary>
        public string Policy { get; set; }

        /// <summary>
        /// 市场
        /// </summary>
        public MarketType Market { get; set; }

        /// <summary>
        /// 账号
        /// </summary>
        public string Account { get; set; }

        /// <summary>
        /// 代码
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 买卖方向
        /// </summary>
        public DirectionType Direction { get; set; }

        /// <summary>
        /// K线级别
        /// </summary>
        public int Level { get; set; }

        /// <summary>
        /// K线单位
        /// </summary>
        public KLineUnitType Unit { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        public int Volume { get; set; }

        /// <summary>
        /// 价格
        /// </summary>
        public double Price { get; set; }

        /// <summary>
        /// 唯一键
        /// </summary>
        private string id;

        /// <summary>
        /// 取得唯一键
        /// </summary>
        /// <returns>唯一键</returns>
        public string GetId()
        {
            if (id == null)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();

                sb.Append(Market.ToString()).Append("_")
                  .Append(Policy).Append("_")
                  .Append(Account).Append("_")
                  .Append(Code).Append("_")
                  .Append(Direction.ToString()).Append("_")
                  .Append(Level.ToString()).Append("_")
                  .Append(Unit.ToString());

                id = sb.ToString();
            }

            return id;
        }
    }
}
